package com.weetop.aklyscan.activity;

import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.activity.qingdan.InfoDialog2;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.RecordListBean;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InRecordActivity2 extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private CommonRecyclerAdapter<RecordListBean> adapter;
    private List<RecordListBean> list = new ArrayList<>();
    private String order_type, order_sn, date;

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_in_record_1);
        ButterKnife.bind(this);
        order_sn = getIntent().getStringExtra("order_sn");
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<RecordListBean>(mActivity, R.layout.item_record_1, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, RecordListBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                helper.setText(R.id.tv_sn_code, item.getSerial_code());
                helper.setText(R.id.tv_model, item.getGoods_model());
                helper.setText(R.id.tv_name, item.getGoods_name());
                helper.setText(R.id.tv_xiang, item.getTransit_code());
                helper.setText(R.id.tv_huojia, item.getWarehouse_coordinates());
            }
        };
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
        mPresenter.Into27("2", order_sn);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
        InfoDialog2 infoDialog2 = new InfoDialog2(this, list.get(i).getRk_time(), list.get(i).getApply_user_name());
        infoDialog2.show();
    }

    @Override
    public void getInto27Success(BaseModel<List<RecordListBean>> o) {
        List<RecordListBean> listBeans = o.getData();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
    }

//    @Override
//    public void getInto28Success(BaseModel<List<RecordBean>> o) {
//        List<RecordBean> listBeans = o.getData();
//        list.clear();
//        adapter.clear();
//        list.addAll(listBeans);
//        adapter.addAll(listBeans);
//    }
}